[jQuery] Sort contents alphabetically
Posted
by James
on Stack Overflow
See other posts from Stack Overflow
or by James
Published on 2010-06-12T02:22:30Z
Indexed on
2010/06/12
2:32 UTC
Read the original article
Hit count: 208
jQuery
So I am appending the following after an AJAX call, and this AJAX call may happen several time, returning several data items. And I am trying to use Tinysort [http://plugins.jquery.com/project/TinySort] to sort the list everytime, so the new items added are integrated nicely and sorted alphabetically.
It unfortunately doesn't seem to be working. Any ideas? I mean, the data itself is being correctly appended, but unfortunately the sorting isn't occurring.
var artists = [];
$.each(data.artists, function(k, v) {
artists.push('<section id="artist:' + v.name + '" class="artist"><div class="span-9"><img alt="' + v.name + '" width="34" height="34" class="photo" src="' + v.photo + '" /><strong>' + v.name + '</strong><br/><span>' + v.events + ' upcoming gig');
if (v.events != 1) {
artists.push('s');
}
artists.push('</span></div><div class="span-2 align-right last">Last</div><div class="clear"></div></section>');
});
$('div.artists p').remove();
$('div.artists div.next').remove();
$('div.artists').append(artists.join('')).append('<div class="next"><a href="#">Next</a></div>');
$('div.artists section').tsort('section[id]', {orderby: 'id'});
Thanks!
© Stack Overflow or respective owner